<?php
class Pagination {
function display($params) {
        $current = $params['current_page'];
        $total = $params['total_page'];
        $limit = $total/PER_PAGE;
        if($limit%PER_PAGE != 0)
        {
            $limit = ceil($limit);
        }
        $html = '<li class="active"><a href="#">'.$current.'</a></li>';
        if(($current > 0 && $current < ($limit + 1))&& is_int($current*1)){
            for ($i = 1; $i < $limit; $i++){
                $next_page = $current + $i;
                if ($next_page <= $limit && $next_page <= $current + 2) {
                    $html .= '<li><a href="'.$params['file']."?page={$next_page}".'">'.$next_page.'</a></li>';
                }
                $prev_page = $current - $i;
                if ($prev_page  > 0 && $prev_page > $current - 2) {                
                        $html = '<li><a href="'.$params['file']."?page={$prev_page}".'">'.$prev_page.'</a></li>'.$html;
                    
                }
            }
            if($current > 2)
            {
                echo '<li><a href="'.$params['file']."?page=1".'">1</a></li>';
                echo '<li><a href="#">...</a></li>';
            }
          
            echo $html;
            if($current < $limit - 2)
            {
                echo '<li><a href="#">...</a></li>';
                echo '<li><a href="'.$params['file']."?page={$limit}".'">'.$limit.'</a></li>';
            }
        }
        else
        {
            print'<script type="text/javascript">';
            print'location.href = "error.php";';
            print'</script>';
        }
    }
    function display2($params) {
        $current = $params['current_page'];
        $total = $params['total_page'];
        $limit = $total/PER_PAGE;
        if($limit%PER_PAGE != 0)
        {
            $limit = ceil($limit);
        }
        $html = '<li class="active"><a href="#">'.$current.'</a></li>';
        if(($current > 0 && $current < ($limit + 1))&& is_int($current*1)){
            for ($i = 1; $i < $limit; $i++){
                $next_page = $current + $i;
                if ($next_page <= $limit && $next_page <= $current + 2) {
                    $html .= '<li><a href="'.$params['file']."&page={$next_page}".'">'.$next_page.'</a></li>';
                }
                $prev_page = $current - $i;
                if ($prev_page  > 0 && $prev_page > $current - 2) {                
                        $html = '<li><a href="'.$params['file']."&page={$prev_page}".'">'.$prev_page.'</a></li>'.$html;
                    
                }
            }
            if($current > 2)
            {
                echo '<li><a href="'.$params['file']."&page=1".'">1</a></li>';
                echo '<li><a href="#">...</a></li>';
            }
          
            echo $html;
            if($current < $limit - 2)
            {
                echo '<li><a href="#">...</a></li>';
                echo '<li><a href="'.$params['file']."&page={$limit}".'">'.$limit.'</a></li>';
            }
        }
        else
        {
            print'<script type="text/javascript">';
            print'location.href = "error.php";';
            print'</script>';
        }
    }
    function display4($params) {
        $current = $params['current_page'];
        $total = $params['total_page'];
        $limit = $total/PER_PAGE;
        if($limit%PER_PAGE != 0)
        {
            $limit = ceil($limit);
        }
        $html = '<li class="active"><a href="#">'.$current.'</a></li>';
        if(($current > 0 && $current < ($limit + 1))&& is_int($current*1)){
            for ($i = 1; $i < $limit; $i++){
                $next_page = $current + $i;
                if ($next_page <= $limit && $next_page <= $current + 2) {
                    $html .= '<li><a href="'.$params['file']."?page={$next_page}".'">'.$next_page.'</a></li>';
                }
                $prev_page = $current - $i;
                if ($prev_page  > 0 && $prev_page > $current - 2) {                
                        $html = '<li><a href="'.$params['file']."?page={$prev_page}".'">'.$prev_page.'</a></li>'.$html;
                    
                }
            }
            if($current > 2)
            {
                echo '<li><a href="'.$params['file']."?page=1".'">1</a></li>';
                echo '<li><a href="#">...</a></li>';
            }
          
            echo $html;
            if($current < $limit - 2)
            {
                echo '<li><a href="#">...</a></li>';
                echo '<li><a href="'.$params['file']."?page={$limit}".'">'.$limit.'</a></li>';
            }
        }
        else
        {
            print'<script type="text/javascript">';
            print'location.href = "'.HOST.'view/view_out.php";';
            print'</script>';
        }
    }
}
?>
